package com.globalresources.dao.hibernate;

import java.util.List;

import com.globalresources.commons.StringHelper;
import com.globalresources.dao.inface.IRelationDao;
import com.globalresources.po.Relation;
import com.trg.dao.dao.standard.GenericDAOImpl;
import com.trg.search.Filter;
import com.trg.search.Search;

/**
 * @author aaron.lu(luzhiyuan) E-mail:atyuan.lu@gmail.com
 * @since 创建时间：Jul 14, 2009 12:12:40 AM
 */
public class RelationDaoHibernate extends GenericDAOImpl<Relation, Integer> implements IRelationDao{
	
	/**
	 * query the relation data
	*@author aaron.lu(luzhiyuan)
	*@param username
	*@param authority
	*@return List Relation
	 */
	public List<Relation> getRelations(String username, String authority){
		Search search = new Search();		
		/*
		 * add some filter
		 */
		search.addFilterEqual("user.username", username);
		search.addFilterEqual("authority.authority", authority);
		return super.search(search);
	}
	
	/**
	 * count the relation by username or autority
	*@author aaron.lu(luzhiyuan)
	*@param username
	*@param authority
	*@return int 
	 */
	public int countRelations(String username, String authority){
		Search search = new Search();

		/*
		 * add some filter
		 */
		search.addFilterEqual("user.username", username);
		search.addFilterEqual("authority.authority", authority);
		return super.count(search);
	}
}
